/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.trainning.huongpq.btvn2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Arrays;

/**
 *
 * @author Admin_Pro
 */

//bai 7 em lam luon cho bai 8, bai 9 vi no cung tuong tu nhu nha
//OK
public class Bai7 {

    public static void main(String[] args) {
        File f = new File("bai 7.txt");
        try {
            f.createNewFile();
            FileReader fr = new FileReader(f);
            BufferedReader br = new BufferedReader(fr);
            String a;
            try {
                a = br.readLine();
                StringTokenizer s = new StringTokenizer(a);
                long m = 0;
                System.out.println("cac tu trong xau da xap xep: ");
                String[] tu = new String[10000];
                int i = 0;
                while (s.hasMoreTokens()) {
                    tu[i++] = s.nextToken();
                    m = Math.max(m, tu[i - 1].length());
                }               
                Arrays.sort(tu,0,i);
                for(int j = 0;j<i;j++){
                    System.out.print(tu[j]+" ");
                }
                System.out.println("");
                System.out.println("cac tu co do dai dai nhat la: ");
                for(int j=0;j<i;j++){
                    if(tu[j].length()==m) System.out.println("tu: " + tu[j] + " vi tri bat dau trong chuoi: " + a.indexOf(tu[j]));
                }
            } catch (Exception e) {
                System.out.println("loi: " + e);
            }
        } catch (IOException ex) {
            Logger.getLogger(Bai7.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
